package leetcode.code0199;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

import leetcode.IDebug;
import leetcode.helper.tree.TreeNode;

/**
 * 执行用时：1 ms, 在所有 Java 提交中击败了81.52%的用户
 *
 * 内存消耗：37.1 MB, 在所有 Java 提交中击败了40.93%的用户
 *
 * 通过测试用例：215 / 215
 */
public class Solution implements IDebug {

	public List<Integer> rightSideView(TreeNode root) {
		List<Integer> ans = new ArrayList<>();
		if (root == null) {
			return ans;
		}
		Queue<TreeNode> queue = new LinkedList<>();
		queue.add(root);
		TreeNode tn = null;
		while (!queue.isEmpty()) {
			int size = queue.size();
			while (size > 0) {
				tn = queue.poll();
				if (tn.left != null) {
					queue.add(tn.left);
				}
				if (tn.right != null) {
					queue.add(tn.right);
				}
				size--;
			}
			ans.add(tn.val);
		}
		return ans;
	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
